<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            !function(){
                var classes = {
                    className:"1705班",
                    studentCountNumber:27,
                    students:[
                        {name:"张三",chinese:12,maths:20,english:10,sum:42},
                        {name:"李四",chinese:10,maths:20,english:10,sum:40},
                        {name:"王二",chinese:20,maths:20,english:10,sum:50},

                    ],
                    addStudent:function(){
                        var name = prompt("请输入学员姓名：");
                        var chinese = parseFloat(prompt("请输入学员语文成绩"));
                        var maths = parseFloat(prompt("请输入学员数学成绩"));
                        var english = parseFloat(prompt("请输入学员英语成绩"));
                        var sum = chinese+maths+english;
                        var student ={
                            name:name,
                            chinese:chinese,
                            maths:maths,
                            english:english,
                            sum:sum
                        }
                        this.students.push(student);
                    },
                    showStudent:function(){
                        var arr = classes.students;
                        console.log("\t\t\t杰瑞教育1705班成绩展示");
                        console.log("序号\t姓名\t语文\t数学\t英语\t总分");
                        arr.sort(function(a,b){
                            return b.sum-a.sum;
                        });
                        arr.forEach(function(item,index){
                            console.log((index+1)+"\t\t"+item.name+"\t"
                            +item.chinese+"\t\t"+item.maths+"\t\t"+item.english+"\t\t"+item.sum);

                        });
                    },
                    delStudent:function(){
                        if(this.students.length<=0){
                            alert("没有学员信息,无法删除");
                            return;
                        }
                        var no = prompt("请输入要删除的学员序号！");
                        if(no<1||no>this.students.length){
                            alert("序号输入有误！请重新输入学员序号！");
                            return;
                            
                            }
                       
                    
                    this.students.splice(no-1);
                },

            }
            console.log("\t\t\t杰瑞教育学生成绩管理系统");
            console.log("1.学员成绩录入\t2.展示所有学员成绩\t3.删除学员信息");
                while(true){
                    var sel=parseInt(prompt("请选择操作序号："));
                    switch(sel){
                        case 1:
                            classes.addStudent();
                            console.log("录入成功！");
                            classes.showStudent();
                            console.log("是否继续(N退出)");
                            break;
                        case 2:
                            classes.showStudent();
                            break;
                        case 3:
                            classes.delStudent();
                            console.log("删除成功！");
                            classes.showStudent();
                            console.log("是否继续(N退出)");
                            break;
                    }
                    var isGo = prompt("输入N退出,输入其他字符继续");
                    if(isGo=="N"||isGo=="n"){
                        console.log("成功退出!感谢使用");return;

                    }else continue;
                }
            }();
            </script>
    </body>
</html>